package cn.concurrence.blockqueue;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;

/**
 * @author summit
 * @since 2022/4/24 17:50
 */
public class SynchronousQueueTest {

	public static void main(String[] args) {
		BlockingQueue<Integer> bq = new SynchronousQueue<>();

		new Thread(()->{
			try {
				bq.put(1);
				bq.put(2);
				bq.put(3);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}

		}).start();

		new Thread(()->{
			try {
				System.out.println(bq.take());
				TimeUnit.SECONDS.sleep(3);
				System.out.println(bq.take());
				TimeUnit.SECONDS.sleep(3);
				System.out.println(bq.take());
			} catch (InterruptedException e) {
				e.printStackTrace();
			}

		}).start();
	}
}
